//
//  GoodsDetailCtr-header.swift
//  smosky
//
//  Created by zhu xietong on 2018/5/21.
//  Copyright © 2018年 tianrun. All rights reserved.
//

import Foundation
import soapp
import Eelay
extension GoodsDetailCtr{
    open class CoversView: JoView,EeActionDelegate{
        
        public var justHeight:CGFloat{
            get{
                let just = self.mo.controller?.topLayoutGuide.length ?? TP.topHeight
                return just
            }
        }
        public var miniHeigth:CGFloat{
            get{
                return self.frame.size.height + justHeight
            }
        }
        
        public var heightLayoutConstraint = NSLayoutConstraint()
        
        public let containerView = UIView()
        public var loopview = EeLoopView<LopKit>(frame: [0,0,Swidth,CGFloat(3.5/6.0)])
        public class LopKit: EeKit {
            public let imgV = UIImageView()
            public let titleL = UILabel()
            public override func addLayoutRules() {
                eelay = [
                    [imgV,[ee.T.L.B.R]],
                ]
            }
            
            override public func mo_model_reload() {
                imgV.img_url = mo.model["img",""]
            }
        }
        
        public func active(onwer: Any, actionID: String, data: NSMutableDictionary) {
            if actionID.hasPrefix("tap")
            {
                //                let ctr = ZixunWebCtr()
                //                ctr.info = data
                //                self.content_controller?.navigationController?.pushViewController(ctr, animated: true)
            }
            
        }
        
        func addLoopView() {
            //            let h = Swidth * CGFloat(3.5/6.0)
            //            containerView.eelay = [
            //                [loopview,[ee.T.L.B.R],"\(h)"],
            //            ]
            loopview.pageControl.alpha = 1.0
            loopview.deletate = self
        }
        override open func mo_model_reload() {
            loopview.datas = DataNode.path(node: "options", mo.model, value: NSMutableArray())
        }
        
        
        
        
        
        override open func addLayoutRules() {
            self.backgroundColor = UIColor._background
            
        }
        
        override open func mo_set_controller(controller: UIViewController) {
            
            self.eelay = [
                [containerView,[ee.L.R.B]],
            ]
            
            self.heightLayoutConstraint = NSLayoutConstraint(item: containerView, attribute:.height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1, constant: self.miniHeigth)
            self.addConstraint(heightLayoutConstraint)
            containerView.eelay = [
                [loopview,[ee.T.L.B.R]]
            ]
            
            addLoopView()
        }
        
        
        open func scrollViewDidScroll(scrollView: UIScrollView) {
            let offsetY = (-scrollView.contentOffset.y) - justHeight
            //            print("=========----|\(offsetY)")
            if offsetY < 0{
                return
            }
            self.heightLayoutConstraint.constant = miniHeigth+offsetY
            self.containerView.layoutIfNeeded()
            containerView.clipsToBounds = offsetY <= 0
        }
    }

}
